package net.huashitong.user.service;

import java.util.ArrayList;
import java.util.List;

import net.huashitong.Indicators.dataBean.IndexDataDTO;
import net.huashitong.user.dao.CollectionDao;
import net.huashitong.user.entity.Collection;
import net.huashitong.user.filter.CollectionFilter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sirdc.modules.core.dao.BaseDao;
import com.sirdc.modules.sys.base.StringPKService;
import com.sirdc.modules.sys.service.SysTableService;

@Service
public class CollectionService extends StringPKService<Collection> {
	@Autowired
	private SysTableService tableService;
	@Autowired
	private CollectionDao dao;
	@Override
	protected BaseDao<Collection, String> getDao() {
		// TODO Auto-generated method stub
		return dao;
	}
	@Override
	protected void beforeSave(Collection collection) {
		collection.setSysId(tableService.updateMaxSysId("t_gis_collection", null));
	}
	public List<Collection> queryByUserId(CollectionFilter filter) {
		return dao.queryByUserId(filter);
	}
	/*public Collection getByuserIdAndAlertId(EarlyWarnFilter filter) {
		return dao.getByuserIdAndAlertId(filter);
	}*/
	public Collection getByUserIdAndAlertId(CollectionFilter filter) {
		return dao.getByUserIdAndAlertId(filter);
	}

	public List<Collection> query(CollectionFilter filter){
		return dao.query(filter);
	}

	public List<IndexDataDTO> getCollects(String keyword,String userid)
	{

		List<IndexDataDTO> list =  new ArrayList<>();

		CollectionFilter filter  = new CollectionFilter();
		filter.setAreaName(keyword);
		filter.setUserId( userid);
		List<IndexDataDTO>  dto1 =dao.querySearchCollection(filter);
		list.addAll(dto1);


		filter = new CollectionFilter();
		filter.setDatetime(keyword);
		filter.setUserId( userid);
		List<IndexDataDTO> dto2 = dao.querySearchCollection(filter);
		list.addAll(dto2);


		filter = new CollectionFilter();
		filter.setCodeName(keyword);
		filter.setUserId( userid);
		List<IndexDataDTO> dto3 = dao.querySearchCollection(filter);
		list.addAll(dto3);


		return list;
	}

}
